-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bitbucket Server] Implements the GetMe method #128
base: bitbucket-server
Are you sure you want to change the base?
[Bitbucket Server] Implements the GetMe method #128
Conversation
Hello @panoramix360, Thanks for your pull request! A Core Committer will review your pull request soon. For code contributions, you can learn more about the review process here. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## bitbucket-server #128 +/- ##
===================================================
Coverage ? 15.58%
===================================================
Files ? 15
Lines ? 2439
Branches ? 0
===================================================
Hits ? 380
Misses ? 2035
Partials ? 24 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking great @panoramix360! I left some comments on relocating BitBucket Server code to its own package, and managing the token for the client via the oauth2.Client
instead of creating a http.Client
directly. Otherwise LGTM 👍
server/client_server_test.go
Outdated
} | ||
|
||
w.WriteHeader(http.StatusOK) | ||
w.Write([]byte("mocked-user")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can do this to intentionally ignore the error, and avoid the lint issue:
w.Write([]byte("mocked-user")) | |
_ = w.Write([]byte("mocked-user")) |
server/client_server_test.go
Outdated
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
authHeader := r.Header.Get("Authorization") | ||
if authHeader != "Bearer valid-token" { | ||
w.WriteHeader(http.StatusUnauthorized) | ||
return | ||
} | ||
|
||
w.WriteHeader(http.StatusOK) | ||
w.Write([]byte("mocked-user")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have a similar test for the GetUser
call? Maybe have one main "test" for ourBitbucketClient.GetMe
, and have one of the test cases be a success case that returns a real user from the http server. Nice testing!
This PR has been automatically labelled "stale" because it hasn't had recent activity. |
hey @mickmister I added a Factory Pattern as we discussed, I think this approach is cleaner, can you review it again? Meanwhile, I'll take a look and solve the other comments. Can you take a look at some comments that I made as well? Thanks! |
server/bitbucket_server/factory.go
Outdated
func GetBitbucketClient(clientType string, selfHostedURL string, selfHostedAPIURL string, apiClient *bitbucketv1.APIClient) (Client, error) { | ||
if clientType == "server" { | ||
return newServerClient(selfHostedURL, selfHostedAPIURL, apiClient), nil | ||
} | ||
return nil, fmt.Errorf("wrong client passed") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this package only creates a Bitbucket Server client, and not a Bitbucket Cloud client, what benefit do we get from having this clientType
parameter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, the idea is to create the Bitbucket Cloud as well! I didn't insert this yet because we plan to do this more consistently on this issue.
But if you want, I can add the condition here. Let me know what you think!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the function to create the BB Cloud client will be in a separate package though like bitbucket_cloud
. What do you think? We'll see how the code feels when instantiating either client from the main package
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can change the name of this package to just package bitbucket
and have both on the same package.
so we have:
client.go
: generic client with the necessary methodsclient_server
: concrete server client with the implementation of the Bitbucket Serverclient_cloud
: concrete cloud client with the implementation of the Bitbucket Cloud
What do you think of this approach?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we think that everything to do with Bitbucket Server can/should fit in its own file, then this works well. But if there are multiple files for each client type, I think we should have separate packages for each client type. What do you think?
So either this that I think you're suggesting
client := bitbucket.NewBBServerClient()
or
client := bitbucket_server.NewClient()
Hi @panoramix360, this is looking good 👍 Are you able to resolve the lint issues CI is reporting? Thank you! |
hey @mickmister, done! I needed to change the name of the package, and it made more sense to call it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍 Just some comments for discussion. Great work @panoramix360!!
SelfHostedURL string | ||
SelfHostedAPIURL string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been thinking that this SelfHostedAPIURL
is derived from SelfHostedURL
(we just add some suffix to it), so maybe we can have just one config setting SelfHostedURL
, and derive SelfHostedAPIURL
at runtime?
func GetBitbucketClient(clientType string, config ClientConfiguration) (Client, error) { | ||
if clientType == "server" { | ||
return newServerClient(config), nil | ||
} | ||
return nil, fmt.Errorf("wrong client passed") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just an idea, but I'm thinking having two different functions for creating the two clients may be more Go-idiomatic. So having a NewBBServerClient()
function for instance to create the BB Server client
BitbucketClient | ||
} | ||
|
||
func newServerClient(config ClientConfiguration) Client { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we would make this function capitalized/exported if we want to expose it
Summary
This is the first PR to begin the implementation of the Bitbucket Server in the Plugin.
It creates the
client_server.go
to integrate the Bitbucket Server methods to the Plugin, I implemented the first oneGetMe
this one does two requests to complete:This flow is needed because the Bitbucket Server API doesn't have the same methods of the Bitbucket Cloud like
/user
that already accounts for the logged user.Ticket Link
Github Issue